package com.ete.app.viewAdapter

import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import androidx.databinding.BindingAdapter
import androidx.databinding.ObservableInt
import com.blankj.utilcode.util.ResourceUtils
import com.blankj.utilcode.util.SizeUtils

/**
 * Author:LiXian
 * <p>
 * Desc:TODO
 * Version:1.0
 * date 2025/6/5 14:46
 */
object ViewAdapter {

    @JvmStatic
    @BindingAdapter(value = ["srcRes"], requireAll = false)
    fun setDrawableRes(mIv: ImageView, srcRes: ObservableInt?) {
        if (srcRes == null || srcRes.get() == 0) return
        mIv.setImageResource(srcRes.get())
    }

    @JvmStatic
    @BindingAdapter(value = ["tvLeftDrawable"], requireAll = false)
    fun setTextViewLeft(mTv: TextView, srcRes: ObservableInt?) {
        if (srcRes == null || srcRes.get() == 0) return
        val drawable = ResourceUtils.getDrawable(srcRes.get())
        drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
        mTv.setCompoundDrawables(drawable, null, null, null)
        mTv.compoundDrawablePadding = SizeUtils.dp2px(5F)
    }

}